package com.hejielife.producerconsumer4;

/**
 * 2019年8月2日 下午2:27:13
 * 
 * @author hejielife
 * @despribe Host 可以撤销的任务
 */
public class Host {
	public static void execute(int count) throws InterruptedException {
		for (int i = 0; i < count; i++) {
			// 可以取消这个繁重的任务
			if (Thread.interrupted()) {
				throw new InterruptedException();
			}
			doHeavyJob();
		}
	}

	private static void doHeavyJob() {
		System.out.println("doHeavyJob BEGIN");
		long start = System.currentTimeMillis();
		while (start + 10000 > System.currentTimeMillis()) {
			// busy loop
		}
		System.out.println("doHeavyJob END");
	}
}
